package internal

import (
	"github.com/gin-gonic/gin"
	"github.com/golang-jwt/jwt/v5"
	"net/http"
	"time"
)

var secret = []byte("123456")

func LoginHandler(c *gin.Context) {
	// Demo：直接登录成功，不用数据库
	token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{
		"user": "test",
		"exp":  time.Now().Add(time.Hour).Unix(),
	})

	tokenString, _ := token.SignedString(secret)

	c.JSON(http.StatusOK, gin.H{
		"token": tokenString,
	})
}
